package com.zzq.my.jetpacks.util;

import java.util.Arrays;
import java.util.List;

public class StringUtils {
    /**
     * 将泛型为String类型的集合转化为逗号间隔字符串形式
     *
     *
     */
    public static String stringListToString(List<String> stringList){
        if (stringList == null || stringList.size() <= 0) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (String string:stringList) {
            stringBuffer.append(string + ",");
        }
        return stringBuffer.toString().substring(0, stringBuffer.toString().lastIndexOf(","));
    }

    /**
     * 将泛型为String类型的集合转化为逗号间隔字符串形式
     *
     *
     */
    public static String stringListToString2(List<String> stringList){
        if (stringList == null || stringList.size() <= 0) {
            return null;
        }
        return stringList.toString().replaceAll("^\\[| |\\]$", "");
    }

    /**
     * 将String类型的数组转化为逗号间隔字符串形式
     *
     *
     */
    public static String stringArrayToString(String [] stringArray){
        if (stringArray == null || stringArray.length <= 0) {
            return null;
        }
        return Arrays.toString(stringArray).replaceAll("^\\[| |\\]$", "");
    }


}
